﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 高级控件演示.Views
{
    /// <summary>
    /// SpeekContent.xaml 的交互逻辑
    /// </summary>
    public partial class SpeekContent : UserControl
    {
        public SpeekContent()
        {
            InitializeComponent();
        }


        //private void HighlightText(int startPos, int length,Brush brush)
        //{
        //    var fullText = txtContent.Text;

        //    var currentStr = fullText.Substring(0, startPos);

        //    if (!string.IsNullOrEmpty(currentStr))
        //    {
        //        var lastStr = currentStr.Substring(currentStr.Length - 1, 1);

        //        int ascii = (int)lastStr[0];

        //        Debug.WriteLine($"当前字符串:{lastStr},ASCII码是:{ascii}");
        //        if (ascii == 13 || ascii== 10 )
        //        {
        //            Debug.WriteLine("回车换行，取消处理!");
        //            return;
        //        }
        //    }

            

        //    txtContent.Inlines.Clear();

        //    // 非高亮部分
        //    txtContent.Inlines.Add(new Run(currentStr));

        //    // 高亮部分
        //    var highlightRun = new Run(fullText.Substring(startPos, length))
        //    {
        //        Foreground = brush,
        //        FontWeight = FontWeights.Bold
        //    };
        //    txtContent.Inlines.Add(highlightRun);

        //    // 剩余部分
        //    txtContent.Inlines.Add(new Run(fullText.Substring(startPos + length)));
        //}

        private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            //int length = txtContent.Text.Length;
            //for (int i = 0; i < length; i++)
            //{
            //    HighlightText(i, 1,Brushes.Red);
            //    await Task.Delay(200);
            //}
            //HighlightText(length-1, 1,Brushes.Black);
        }
    }
}
